package com.baizhi.service.impl;

import com.baizhi.dao.BannerDao;
import com.baizhi.entity.Banner;
import com.baizhi.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class BannerServiceImpl implements BannerService {
    @Autowired
    private BannerDao bannerDao;

    @Override
    public Map selectBannerDatagrid(int page, int rows) {
        //查询出轮播图的数量
        int count =bannerDao.selectBannerCount();
        //查询出所有轮播图
        //获取start参数
        int start=(page-1)*rows;
        List<Banner> bannerList=bannerDao.selectBannerDatagrid(start,rows);
        //创建map集合，把count和bannerList放入map
        Map map=new HashMap();
        map.put("total",count);
        map.put("rows",bannerList);
        return map;
    }

    @Override
    public void addBanner(Banner banner) {
        bannerDao.insert(banner);
    }

    @Override
    public void deleteSomeBanners(int[] ids) {
        bannerDao.updateStatus(ids);
    }

    @Override
    public List<Banner> getAllBanner() {

        return bannerDao.getAllBanner();
    }
}
